﻿using lyAdmin.Common;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Routing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;

namespace lyAdmin.Models
{
    public class AuthonizationFilter : Attribute, Microsoft.AspNetCore.Mvc.Filters.IAuthorizationFilter
    { 
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            string token = context.HttpContext.Request.Cookies["token"];
            if (token == null || RedisSingleton.Redis.Get(token+ "userInfo") ==null)
            { 
                context.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "System", action = "Login", area ="admin" }));
            }
        }
    }
}
